<?php namespace Summer\Shop\Models;

use Model;
use System\Models\File;
use Winter\Storm\Database\Traits\NestedTree;

/**
 * Model
 */
class CategoryModel extends Model
{
    use \Winter\Storm\Database\Traits\Validation;
    use NestedTree;

    /**
     * @var string The database table used by the model.
     */
    public $table = 'summer_shop_categories';

    /**
     * @var array Validation rules
     */
    public $rules = [
        'name'=>'required|between:2,255',
    ];
    public $attachOne=[
        'cover'=>File::class,
    ];
    public function getParentOptions()
    {
        $items = $this->id ? CategoryModel::withoutSelf()->get() : CategoryModel::getAll();

        return [
                // null key for "no parent"
                null => '顶级分类',
            ] + $items->listsNested('name', 'id');
    }
}
